import kMeans

# 载入数据集
datMat = kMeans.mat(kMeans.loadDataSet('testSet.txt'))
#datMat = kMeans.mat(kMeans.loadDataSet('testSet2.txt'))

# 输出各维度的最大最小值
print ("最小值：",[min(datMat[:,0]),min(datMat[:,1])])
print ("最大值：",[max(datMat[:,0]),max(datMat[:,1])])

# 测试randCent()函数能否生成min到max之间的值
#kMeans.randCent(datMat, 2)

# 测试distEclud()函数，距离计算是否正确
#kMeans.distEclud(datMat[0], datMat[0])
#kMeans.distEclud(datMat[0], datMat[1])

# 测试K-均值聚类算法
#myCentroids, clusterAssing = kMeans.kMeans(datMat, 4)

# 绘制K-均值聚类结果示意图
#kMeans.plotKMeans(datMat,clusterAssing,myCentroids)

# 测试二分K-均值聚类算法
myCentroids, clusterAssing = kMeans.biKmeans(datMat, 4)
print ("输出聚类质心结果：")
print (myCentroids)
kMeans.plotKMeans(datMat,clusterAssing,myCentroids)

